<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
    <head>
      <style type="text/css">
        body { font-family: Verdana, Arial }
      </style>
      <script type="text/javascript">
        function ToggleElement(id)
        {
          var element = document.getElementById(id)
          if (element.style.display == 'block')
            element.style.display = 'none';
          else
            element.style.display = 'block';
        }
      </script>
    </head>
    <body>
      <p>
        Number of pages: <xsl:value-of select="count(Pages/Page)"/><br />
        Number of pages with page methods: <xsl:value-of select="count(Pages/Page[Methods/Method])"/><br />
        Number of page methods: <xsl:value-of select="count(Pages/Page/Methods/Method)"/><br />
        Average number of page methods by page: <xsl:value-of select="count(Pages/Page/Methods/Method) div count(Pages/Page[Methods/Method])"/>
      </p>

      Pages:
      <ul>
      <xsl:for-each select="Pages/Page">
        <xsl:sort select="@url"/>
        <li>
          <div onclick="javascript:ToggleElement('{generate-id(.)}')">
            <xsl:if test="Methods/Method">
              <xsl:attribute name="style">cursor: pointer; font-weight: bold</xsl:attribute>
            </xsl:if>
            <xsl:value-of select="@url"/> 
            <xsl:if test="Methods/Method"> (<xsl:value-of select="count(Methods/Method)"/>)</xsl:if>
          </div>
          <ul id="{generate-id(.)}" style="display: none">
            <xsl:for-each select="Methods/Method">
              <xsl:sort select="@name"/>
              <li>
                <xsl:value-of select="@name"/>(<xsl:for-each select="Parameters/Parameter">
                  <xsl:if test="position() != count(.)">, </xsl:if>
                  <xsl:value-of select="@type"/>
                  <xsl:text> </xsl:text>
                  <xsl:value-of select="@name"/>
                </xsl:for-each>)
              </li>
            </xsl:for-each>
          </ul>
        </li>
      </xsl:for-each>
      </ul>
    </body>
  </html>
</xsl:template>

</xsl:stylesheet> 
